package cn.stronglink.asset.module.visitor.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.VisitorRegistration;
import cn.stronglink.asset.module.visitor.service.VisitorService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "visitor")
public class VisitorController extends AbstractController {
	
	@Autowired
	private VisitorService visitorService;
	
	@RequestMapping(value = "getVisitorByParams")
	public ResponseEntity<ModelMap> getVisitorByParams(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {
		
		Page<VisitorRegistration> page = (Page<VisitorRegistration>) super.getPage(params);
		Page<VisitorRegistration> list = visitorService.getVisitorByParams(page, params);
		return setSuccessModelMap(modelMap, list);
	} 
	@OperateLog(module = "人员登记管理",desc="添加人员登记记录", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody VisitorRegistration vr) {
		visitorService.create(vr);
		return setSuccessModelMap(modelMap, null);
	} 
	
	@OperateLog(module = "人员登记管理",desc="人员进入记录", type = OpType.ADD)
	@RequestMapping(value = "entry")
	public ResponseEntity<ModelMap> entry(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody VisitorRegistration vr) {
		visitorService.entry(vr);
		return setSuccessModelMap(modelMap, null);
	} 
	
	@OperateLog(module = "人员登记管理",desc="人员离开记录", type = OpType.ADD)
	@RequestMapping(value = "leave")
	public ResponseEntity<ModelMap> leave(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody VisitorRegistration vr) {
		visitorService.leave(vr);
		return setSuccessModelMap(modelMap, null);
	} 
	
}
